<html>
<head><title>Nicofarre test</title></head>
<body>
<script src="../tma.js"></script>
<script src="mv_common.js"></script>
<script>
tma.extlibs = [ 'ext/gl-matrix.js', 'ext/mv/MajVj.js' ];
tma.onload = function () {
  Promise.all([
    MajVj.loadAllPlugins()
  ]).then(_(function () {
    var r = 1;
    var width = 1920 / r;
    var height = 1080 / r;
    var vj = new MajVj(width, height, true);
    var font = null;
    t = 0;
    nico3d = vj.create('frame', 'nicofarre3d', {
      module: 'roll'
      /*
      init: function (api) {
        font = api.createFont({
          size: 128,
          name: 'Comic Sans MS',
          foreground: 'rgba(10, 60, 50, 255)',
          background: 'rgba(0, 0, 0, 255)',
        }, "Takashi Toyoshima");
        obj = {
          x: (Math.random() - 0.5) * 1000,
          y: (Math.random() - 0.5) * 1000,
          z: -Math.random() * 100000
        };
      },
      clear: function (api) {
        api.clear(api.gl.DEPTH_BUFFER_BIT);
        api.setAlphaMode(true, api.gl.ONE, api.gl.SRC_ALPHA);
        api.fill([0.0, 0.0, 0.0, 0.95]);
      },
      draw: function (api) {
        var x = obj.x * (500 - t) / 500;
        var y = obj.y * (500 - t) / 500;
        var z = obj.z * (500 - t) / 500 - t * 2;
        api.drawCharacter(font, 'T', 1, 1, [x, y, z]);
        if (t != 500)
          t++;
      }
      */
    });
    var fbo = vj.screen().createFrameBuffer(width, height);
    var fx = vj.create('effect', 'nicofarre');
    fx.setController(controller);
    vj.screen().setAlphaMode(false);
    //var c = 0;
    vj.run(function (delta) {
      //c++;
      //if (0 == c % 40) {
      //  c = 0;
      //  tma.log('fps: ' + vj.fps());
      //}
      if (emulate)
        fbo.bind();
      vj.screen().fillColor(0.0, 0.0, 0.0, 1.0);
      vj.screen().setAlphaMode(true, vj.screen().gl.ONE, vj.screen().gl.ONE);
      nico3d.draw(delta);
      if (emulate) {
        vj.screen().bind();
        vj.screen().fillColor(0.0, 0.0, 0.0, 1.0);
        fx.draw(delta, fbo.texture);
      }
      vj.screen().flush();
    });
    window.onresize = function () {
      vj.onresize();
      fx.onresize(vj.aspect());
    };
  }), function (e) { console.log('plugin load error: ' + e); });
};
</script>
</body>
</html>
